import {fileURLToPath, URL} from 'url';
import {defineConfig} from 'vite';
import vue from '@vitejs/plugin-vue';
import eslintPlugin from 'vite-plugin-eslint';
import svgLoader from 'vite-svg-loader';

// https://vitejs.dev/config/
export default defineConfig(env => {
    return {
        base: './',
        server: {
            host: '0.0.0.0'
        },
        css: {
            preprocessorOptions: {
                less: {
                    javascriptEnabled: true,
                    math: 'always'
                }
            },
        },
        plugins: [
            vue(),
            svgLoader({
                svgoConfig: {
                    plugins: [
                        // 移除宽高
                        'removeDimensions',
                        // 保留viewBox
                        'removeViewBox'
                    ]
                }
            }),
            eslintPlugin({
                cache: false
            }),
        ],
        build: {
            rollupOptions: {
                manualChunks(id) {
                    if (id.includes('node_modules')) {
                        return 'vendor';
                    }
                }
            },
            assetsInlineLimit: 8092
        },
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url)),
                'assets': fileURLToPath(new URL('./src/assets', import.meta.url))
            }
        }
    };
});
